# @Time    : 2020/4/9 11:40
# @Author  : wumao
# @Email   : kanhebei@dingtalk.com
import functools
from flask import redirect, url_for, request


def first_page_301(func):
    # 分页模式中  第一页 301定向 至 默认首页
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        if request.view_args.get('page') == 1:
            url_args = request.view_args.copy()
            if 'page' in url_args:
                url_args.pop('page')
            return redirect(url_for(request.endpoint, **url_args), 301)
        return func(*args, **kwargs)
    return wrapper
